// import { initRouter } from '@/router/index'
import router from '@/router/index'

const user = {
    state:{
        routers:JSON.parse(localStorage.getItem('v3-element-plus-menu') || '[]'), //设置路由缓存 
        loginState:false,  //设置登录状态
        loginName:"",
    },
    mutations:{
        SET_ROUTERS(state:any,routes:any){
            state.routers = routes
        },
        SET_LOGIN_STATE(state:any,loginState:any){
            state.loginState = loginState;
        },
        SET_USER_NAME(state:any,loginName:any){
            state.loginName = loginName;
        }
    },
    getters:{
        getLoginState:function(state:any){
            return state.loginState;
        },
        getLoginName:function(state:any){
            return state.loginName;
        }
    },
    actions:{
        GET_ROUTERS_DATA(ctx:any){
            // fetch("/menu.json")
            //     .then((res:any) => res.json())
            //     .then((data:any) => {
                    // ctx.commit('SET_ROUTERS',data.menu)
                    ctx.commit('SET_LOGIN_STATE',true)
                    
                // })
                // .catch((err:any) => {
                //     console.log(err)
                // })
        }
    }
}

export default user